﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Things.Common;
using LTP.Accounts.Bus;
namespace Things.ThingsWeb.GoodsComments
{
    public partial class Modify : Page
    {       

        		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
				{
					Guid CommentsID=new Guid(Request.Params["id"]);
					ShowInfo(CommentsID);
				}
			}
		}
			
	private void ShowInfo(Guid CommentsID)
	{
		Things.BLL.GoodsComments bll=new Things.BLL.GoodsComments();
		Things.Model.GoodsComments model=bll.GetModel(CommentsID);
		this.lblCommentsID.Text=model.CommentsID.ToString();
		this.lblGoodsPriceID.Text=model.GoodsPriceID.ToString();
		this.txtComments.Text=model.Comments;
		this.txtBuyerAccount.Text=model.BuyerAccount;
		this.txtCommentDate.Text=model.CommentDate.ToString();
		this.txtRate.Text=model.Rate.ToString();
		this.txtCommentTitle.Text=model.CommentTitle;

	}

		public void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(this.txtComments.Text.Trim().Length==0)
			{
				strErr+="评论不能为空！\\n";	
			}
			if(this.txtBuyerAccount.Text.Trim().Length==0)
			{
				strErr+="用户不能为空！\\n";	
			}
			if(!PageValidate.IsDateTime(txtCommentDate.Text))
			{
				strErr+="评论时间格式错误！\\n";	
			}
			if(!PageValidate.IsDecimal(txtRate.Text))
			{
				strErr+="评分格式错误！\\n";	
			}
			if(this.txtCommentTitle.Text.Trim().Length==0)
			{
				strErr+="评论标题不能为空！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			Guid CommentsID= new Guid(this.lblCommentsID.Text);
			Guid GoodsPriceID= new Guid(this.lblGoodsPriceID.Text);
			string Comments=this.txtComments.Text;
			string BuyerAccount=this.txtBuyerAccount.Text;
			DateTime CommentDate=DateTime.Parse(this.txtCommentDate.Text);
			decimal Rate=decimal.Parse(this.txtRate.Text);
			string CommentTitle=this.txtCommentTitle.Text;


			Things.Model.GoodsComments model=new Things.Model.GoodsComments();
			model.CommentsID=CommentsID;
			model.GoodsPriceID=GoodsPriceID;
			model.Comments=Comments;
			model.BuyerAccount=BuyerAccount;
			model.CommentDate=CommentDate;
			model.Rate=Rate;
			model.CommentTitle=CommentTitle;

			Things.BLL.GoodsComments bll=new Things.BLL.GoodsComments();
			bll.Update(model);
			Things.Common.MessageBox.ShowAndRedirect(this,"保存成功！","list.aspx");

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
